package com.fxsh.auth.util;

import org.jose4j.jwk.RsaJsonWebKey;
import org.jose4j.jwk.RsaJwkGenerator;

import java.util.UUID;

/**
 * @Author: lrz
 * @Date: 2020/10/18:14:54
 */
public class RsaJsonWebKeyFactory{
    private volatile static RsaJsonWebKey jwk;
    public static RsaJsonWebKey getInstance(){
        if (jwk == null){
            synchronized(RsaJsonWebKeyFactory.class){
                if (jwk == null){
                    try{
                        jwk = RsaJwkGenerator.generateJwk(2048);
                        jwk.setKeyId(UUID.randomUUID().toString().replaceAll("-", ""));
                    }catch (Exception e){
                        e.printStackTrace();
                    }

                }
            }
        }
        return jwk;
    }
}
